package com.sfm.controller;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
 
import javax.servlet.ServletOutputStream;
 
import net.sf.json.JSONObject;
 
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
 
 
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;
 
 
@Controller
@Namespace("/")
public class EmpAjaxAction extends ActionSupport implements Preparable{  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
//ModelDriven<Emp>,
	

	private Integer curpage;
	
	public Integer getCurpage() {
		return curpage;
	}
 
	public void setCurpage(Integer curpage) {
		this.curpage = curpage;
	}
 
	
	@Action(value="/query")
	public String query() throws IOException{
		
		//String json = JSONObject.fromObject(pe).toString();
		ServletOutputStream os = ServletActionContext.getResponse().getOutputStream();
		//os.write(json.getBytes("utf-8"));
		return NONE;
	}
	
	/*
	 * 
	 * json方法
	 *
	 public void query(Emp emp,OutputStream os){
		if(emp==null || curpage==null){
			emp=new Emp();
			curpage=1;
		}
		String json=JSONObject.fromObject(pe).toString();
		os.write(json);
		}
	 * 
	 * */
	
	@Action("addmybaits")
	public void add() throws IOException{
		ServletOutputStream os = ServletActionContext.getResponse().getOutputStream();
		try {
			//es.add(emp);
			os.write("1".getBytes("utf-8"));
		} catch (Exception e) {
			os.write("0".getBytes("utf-8"));
		}
	}
	
	@Action("delemybaits")
	public void dele() throws IOException{
		ServletOutputStream os = ServletActionContext.getResponse().getOutputStream();
		try {
			//es.dele(emp);
			os.write("1".getBytes("utf-8"));
		} catch (Exception e) {
			os.write("0".getBytes("utf-8"));
		}
	}
	
	@Action("upmybaits")
	public void update() throws UnsupportedEncodingException, IOException{
		ServletOutputStream os = ServletActionContext.getResponse().getOutputStream();
		try {
			//es.update(emp);
			os.write("1".getBytes("utf-8"));
		} catch (Exception e) {
			os.write("0".getBytes("utf-8"));
		}
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		
	}
 
	

}
